package com.net.xpay.common.manager.impl.stat;

import com.google.common.base.Preconditions;
import com.net.xpay.common.manager.stat.CompanyDailyStatManager;
import com.net.common.dao.BasicMapper;
import com.net.common.manager.AbstractManager;
import com.net.xpay.common.dao.stat.CompanyDailyStatMapper;
import com.net.xpay.common.domain.stat.CompanyDailyStat;
import com.net.xpay.common.model.CompanyDailyStatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;


@Component
public class CompanyDailyStatManagerImpl extends AbstractManager<CompanyDailyStat> implements CompanyDailyStatManager {

    @Autowired
    private CompanyDailyStatMapper mapper;


    @Override
    protected BasicMapper<Long, CompanyDailyStat> getMapper() {
        return mapper;
    }

    @Override
    public CompanyDailyStat findByDay(LocalDate day) {
        CompanyDailyStat condition = new CompanyDailyStat();
        condition.setDay(day);
        return getByCondition(condition);
    }

    @Override
    public CompanyDailyStat sumCompanyDailyStat(CompanyDailyStatModel model) {
        Preconditions.checkArgument(model != null);
        return mapper.sumCompanyDailyStat(model);
    }

    @Override
    public CompanyDailyStat getByDay(LocalDate day) {
        CompanyDailyStat condition = new CompanyDailyStat();
        condition.setDay(day);
        return getByCondition(condition);
    }

    @Override
    public List<CompanyDailyStat> listAll() {
        CompanyDailyStat condition = new CompanyDailyStat();
        return listByCondition(condition, new ArrayList<>());
    }
}
